// importM
import 'package:flutter/material.dart';

// ignore: unused_import
import './MyIcon.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(
          title: Text("Flutter App", style: TextStyle(color: Colors.white)),
          backgroundColor: Colors.deepPurple,
        ),
        body: LeftRight(),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.center,
      children: [
        Container(width: 200, height: 200, color: Colors.deepPurple),
        Container(width: 100, height: 100, color: Colors.yellowAccent),
        Text("Hello World"),
        Text("Hello Flutter"),
      ],
    );
  }
}

class StackPosition extends StatelessWidget {
  const StackPosition({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 300,
      height: 300,
      color: Colors.pinkAccent,
      // 相对定位
      child: Stack(
        children: [
          Positioned(
            left: 50,
            top: 50,
            child: Container(width: 100, height: 100, color: Colors.deepPurple),
          ),
          Positioned(
            right: 50,
            bottom: 50,
            child: Container(
              width: 100,
              height: 100,
              color: Colors.yellowAccent,
            ),
          ),
        ],
      ),
    );
  }
}

// 模拟二级导航条
class Top2 extends StatelessWidget {
  const Top2({super.key});

  @override
  Widget build(BuildContext context) {
    // 获取屏幕宽高
    final size = MediaQuery.of(context).size;
    return Stack(
      children: [
        ListView(
          children: [
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
            ListTile(title: Text("我是一个列表")),
          ],
        ),
        Positioned(
          left: 0,
          bottom: 0,
          // 配置子元素的宽高
          width: size.width,
          height: 50,
          child: Container(
            alignment: Alignment.center,
            color: Colors.deepPurpleAccent,
            child: Text("我是二级导航条", style: TextStyle(color: Colors.white)),
          ),
        ),
      ],
    );
  }
}


// 居中
class Aligns extends StatelessWidget {
  const Aligns({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 300,
      height: 300,
      color: Colors.pinkAccent,
      child: Align(
        alignment: Alignment.center,
        child: Text("Hello Flutter"),
      ),
    );
  }
}

class LeftRight extends StatelessWidget {
  const LeftRight({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(
          width: double.infinity,
          height: 50,
          child: Stack(
            children: [
              Positioned(
                left: 10,
                child: Text("Hello Flutter"),
              ),
              Positioned(
                right: 10,
                child: Text("Hello World"),
              )
            ],
          ),
        )
      ],
    );
  }
}

